package helpers;

import java.util.Locale;
import java.util.ResourceBundle;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;

public class UrlHelper{
	public static String getServerUrl(HttpServletRequest request) {
		String url = "";
		String serverName = request.getServerName();
		String port = Integer.toString(request.getServerPort());
		if (serverName.equals("localhost")) {
			url += "http://" + serverName + ":" + port;
		} else {
			url += "http://" + serverName;
		}
		return url;
	}
	
	
	public static Boolean checkIsSubDomain(String domain) {
    	if (Pattern.matches("^[a-zA-Z0-9-]+$", domain.replace("www.", ""))) {
        	return false;
        }
		return true;
	}
	
	public static String getSubDomain(String domain) {
		String subDomain = "";
		
		if (checkIsSubDomain(domain) && !domain.equals("localhost")) {
			String strs[] = domain.split("[.]");
			subDomain = strs[0];
		}
		return subDomain;
	}
}